package com.xiaoshu.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 功能说明： swagger configuration , provider the API html
 * com.xiaoshu.config
 * http://127.0.0.1:8080/v1/score-server/doc.html#  (建议使用此API HTML)
 * http://127.0.0.1:8080/v1/score-server/swagger-ui.html
 * <p>
 * Original @Author: deane.jia-贾亮亮,2021/6/15 9:29
 * <p>
 * Copyright (C)2012-2021 小树盛凯科技 All rights reserved.
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 为当前包下controller生成API文档
                //.apis(RequestHandlerSelectors.basePackage("com.xiaoshu.controller"))
                // 为有@Api注解的Controller生成API文档
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                // 为有@ApiOperation注解的方法生成API文档
                // .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("score server 服务")
                .description("score server 服务")
                .version("1.0")
                .build();
    }
}
